import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;

import org.omg.CORBA.portable.UnknownException;


public class socket {
	public static void main(String[] args) throws IOException{
		BufferedReader cr = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Enter a message");
		String msg = cr.readLine() + "\nEND\n";
		try{
			Socket s = new Socket("localhost", 2358);
			BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
			BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));

			bw.write(msg);
			bw.flush();

			String input = "";
			String total = "";

			while(input != null){
				total += input;
				input = br.readLine();
			}
			System.out.println(total);
			br.close();
			s.close();
			bw.close();
		} catch (UnknownException e){
			e.getMessage();
		} catch (IOException e){
			e.getMessage();
		}
	}

}
